<template>
  <div class="dashboard-container">
    <div class="app-container" v-permission="['ADMIN', 'dashboard::index']">
      <!-- type -->
      <div>
        <el-radio-group v-model="chartsType1" size="small">
          <el-radio-button label="0">总数据概览</el-radio-button>
          <el-radio-button label="1">批量有密</el-radio-button>
          <el-radio-button label="2">安全发</el-radio-button>
        </el-radio-group>
      </div>
      <!-- 经营数据 -->
      <!-- 标题 -->
      <div class="title1">
        <span>经营数据</span>
      </div>
      <!-- searchModel -->
      <div>
        <el-card shadow="never" class="m-b-8">
          <div>
            <el-form :inline="true" size="mini" class="demo-form-inline">
              <el-radio-group
                v-model="dataType2"
                size="small"
                @change="switchInfo"
              >
                <el-radio-button label="">今日</el-radio-button>
                <el-radio-button label="1">昨日</el-radio-button>
                <el-radio-button label="2">月</el-radio-button>
              </el-radio-group>

              <el-form-item class="m-l-24">
                <el-button type="danger" plain @click="totalSwitchInfo"
                  >历史总量</el-button
                >
              </el-form-item>
            </el-form>
          </div>
        </el-card>
      </div>

      <!-- 时间 -->
      <div class="m-t-16" v-if="dataType2 === ''">
        <span
          >更新时间：{{ sumData.updateTime ? sumData.updateTime : "-" }}</span
        >
      </div>

      <!-- 时间 -->
      <div class="m-t-16" v-if="dataType2 === '1'">
        <span>昨日：{{ yesterday }}</span>
      </div>

      <!-- 时间 -->
      <div class="m-t-16" v-if="dataType2 === '2'">
        <span class="m-l-8" v-if="dayOfMonth != 1"
          >{{ monthStart }}~{{ yesterday }}</span
        >
        <span class="m-l-8" v-if="dayOfMonth == 1">月数据每月1号以后生成</span>
      </div>
      <!-- 时间 -->
      <div class="m-t-16" v-if="dataType2 === '0'">
        <span>起始时间：2023年11月1号~最早时间：昨天</span>
      </div>
      <!-- 内容 -->
      <div class="sumBox">
        <div class="sumItem">
          <span class="m-t-8">新增商户数</span>
          <div class="sumdata1">
            <span>{{
              sumData.registerCount ? sumData.registerCount : "0"
            }}</span>
            <span class="m-l-8">家</span>
          </div>
        </div>

        <div class="sumItem">
          <span class="m-t-8">活跃商户数</span>
          <div class="sumdata2" v-if="chartsType1 === '0'">
            <div class="m-t-8">
              <span>P：</span>
              <span>{{
                sumData.payTransActiveUserCount
                  ? sumData.payTransActiveUserCount
                  : "0"
              }}</span>
            </div>

            <div class="m-t-8">
              <span>A：</span>
              <span>{{
                sumData.safePayActiveUserCount
                  ? sumData.safePayActiveUserCount
                  : "0"
              }}</span>
            </div>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '1'">
            <span>{{
              sumData.payTransActiveUserCount
                ? sumData.payTransActiveUserCount
                : "0"
            }}</span>
            <span class="m-l-8"></span>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '2'">
            <span>{{
              sumData.safePayActiveUserCount
                ? sumData.safePayActiveUserCount
                : "0"
            }}</span>
            <span class="m-l-8"></span>
          </div>
        </div>

        <div class="sumItem">
          <span class="m-t-8">活跃渠道数</span>
          <div class="sumdata2" v-if="chartsType1 === '0'">
            <div class="m-t-8">
              <span>P：</span>
              <span
                >{{
                  sumData.payTransActivePartnerCount
                    ? sumData.payTransActivePartnerCount
                    : "0"
                }}
                家</span
              >
            </div>

            <div class="m-t-8">
              <span>A：</span>
              <span
                >{{
                  sumData.safePayActivePartnerCount
                    ? sumData.safePayActivePartnerCount
                    : "0"
                }}
                家</span
              >
            </div>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '1'">
            <span>{{
              sumData.payTransActivePartnerCount
                ? sumData.payTransActivePartnerCount
                : "0"
            }}</span>
            <span class="m-l-8">家</span>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '2'">
            <span>{{
              sumData.safePayActivePartnerCount
                ? sumData.safePayActivePartnerCount
                : "0"
            }}</span>
            <span class="m-l-8">家</span>
          </div>
        </div>

        <div class="sumItem">
          <span class="m-t-8">服务费充值</span>
          <div class="sumdata1">
            <span>{{
              sumData.serviceChargeFee ? sumData.serviceChargeFee : "0"
            }}</span>
            <span class="m-l-8">元</span>
          </div>
        </div>
      </div>

      <!-- 内容2 -->
      <div class="sumBox">
        <div class="sumItem1">
          <span class="m-t-8">付款金额</span>
          <div class="sumdata2" v-if="chartsType1 === '0'">
            <div>
              <span>{{
                sumData.totalSuccessTransAmount
                  ? sumData.totalSuccessTransAmount
                  : "0"
              }}</span>
              <span class="m-l-8">元</span>
            </div>

            <div class="m-t-8">
              <span>P：</span>
              <span>{{
                sumData.payTransSuccessAmount
                  ? sumData.payTransSuccessAmount
                  : "0"
              }}</span>
            </div>

            <div class="m-t-8">
              <span>A：</span>
              <span>{{
                sumData.safePayTransSuccessAmount
                  ? sumData.safePayTransSuccessAmount
                  : "0"
              }}</span>
            </div>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '1'">
            <span>{{
              sumData.payTransSuccessAmount
                ? sumData.payTransSuccessAmount
                : "0"
            }}</span>
            <span class="m-l-8">元</span>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '2'">
            <span>{{
              sumData.safePayTransSuccessAmount
                ? sumData.safePayTransSuccessAmount
                : "0"
            }}</span>
            <span class="m-l-8">元</span>
          </div>
        </div>

        <div class="sumItem">
          <span class="m-t-8">付款总笔数</span>
          <div class="sumdata2" v-if="chartsType1 === '0'">
            <div>
              <span>成功</span>
              <span class="m-l-4"
                >{{
                  sumData.totalSuccessCount ? sumData.totalSuccessCount : "0"
                }}笔</span
              >
            </div>

            <div class="m-t-8">
              <span>失败</span>
              <span class="m-l-4"
                >{{
                  sumData.totalFailCount ? sumData.totalFailCount : "0"
                }}笔</span
              >
            </div>
          </div>

          <div class="sumdata2" v-if="chartsType1 === '1'">
            <div>
              <span>成功</span>
              <span class="m-l-4"
                >{{
                  sumData.payTransSuccessCount
                    ? sumData.payTransSuccessCount
                    : "0"
                }}笔</span
              >
            </div>

            <div class="m-t-8">
              <span>失败</span>
              <span class="m-l-4"
                >{{
                  sumData.payTransFailCount ? sumData.payTransFailCount : "0"
                }}笔</span
              >
            </div>
          </div>

          <div class="sumdata2" v-if="chartsType1 === '2'">
            <div>
              <span>成功</span>
              <span class="m-l-4"
                >{{
                  sumData.safePayTransSuccessCount
                    ? sumData.safePayTransSuccessCount
                    : "0"
                }}笔</span
              >
            </div>

            <div class="m-t-8">
              <span>失败</span>
              <span class="m-l-4"
                >{{
                  sumData.safePayTransFailCount
                    ? sumData.safePayTransFailCount
                    : "0"
                }}笔</span
              >
            </div>
          </div>
        </div>

        <div class="sumItem">
          <span class="m-t-8">成功支付率</span>

          <div class="sumdata2" v-if="chartsType1 === '0'">
            <div class="m-t-8">
              <span>P：</span>
              <span
                >{{
                  sumData.payTransSuccessRate
                    ? sumData.payTransSuccessRate
                    : "0"
                }}
                %</span
              >
            </div>

            <div class="m-t-8">
              <span>A：</span>
              <span
                >{{
                  sumData.safePaySuccessRate ? sumData.safePaySuccessRate : "0"
                }}
                %</span
              >
            </div>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '1'">
            <span
              >{{
                sumData.payTransSuccessRate ? sumData.payTransSuccessRate : "0"
              }}
              %</span
            >
          </div>

          <div class="sumdata1" v-if="chartsType1 === '2'">
            <span
              >{{
                sumData.safePaySuccessRate ? sumData.safePaySuccessRate : "0"
              }}
              %</span
            >
          </div>
        </div>

        <div class="sumItem">
          <span class="m-t-8">单笔超过500元笔数</span>
          <div class="sumdata2" v-if="chartsType1 === '0'">
            <div>
              <span>成功</span>
              <span class="m-l-4">{{
                sumData.totalSuccessSingleVeryCount
                  ? sumData.totalSuccessSingleVeryCount
                  : "0"
              }}</span>
            </div>

            <div class="m-t-8">
              <span>失败</span>
              <span class="m-l-4">{{
                sumData.totalFailSingleVeryCount
                  ? sumData.totalFailSingleVeryCount
                  : "0"
              }}</span>
            </div>
          </div>

          <div class="sumdata2" v-if="chartsType1 === '1'">
            <div>
              <span>成功</span>
              <span class="m-l-4">{{
                sumData.payTransSuccessSingleVeryCount
                  ? sumData.payTransSuccessSingleVeryCount
                  : "0"
              }}</span>
            </div>

            <div class="m-t-8">
              <span>失败</span>
              <span class="m-l-4">{{
                sumData.payTransFailSingleVeryCount
                  ? sumData.payTransFailSingleVeryCount
                  : "0"
              }}</span>
            </div>
          </div>

          <div class="sumdata2" v-if="chartsType1 === '2'">
            <div>
              <span>成功</span>
              <span class="m-l-4">{{
                sumData.safePayTransSuccessSingleVeryCount
                  ? sumData.safePayTransSuccessSingleVeryCount
                  : "0"
              }}</span>
            </div>

            <div class="m-t-8">
              <span>失败</span>
              <span class="m-l-4">{{
                sumData.safePayTransFailSingleVeryCount
                  ? sumData.safePayTransFailSingleVeryCount
                  : "0"
              }}</span>
            </div>
          </div>
        </div>
      </div>

      <!-- 内容 3-->
      <div class="sumBox">
        <div class="sumItem1">
          <span class="m-t-8">服务费支出</span>
          <div class="sumdata2" v-if="chartsType1 === '0'">
            <div>
              <span>{{
                sumData.totalServicePrice ? sumData.totalServicePrice : "0"
              }}</span>
              <span class="m-l-8">元</span>
            </div>

            <div class="m-t-8">
              <span>P：</span>
              <span>{{
                sumData.payTransServicePrice
                  ? sumData.payTransServicePrice
                  : "0"
              }}</span>
            </div>

            <div class="m-t-8">
              <span>A：</span>
              <span>{{
                sumData.safePayTransServicePrice
                  ? sumData.safePayTransServicePrice
                  : "0"
              }}</span>
            </div>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '1'">
            <span>{{
              sumData.payTransServicePrice ? sumData.payTransServicePrice : "0"
            }}</span>
            <span class="m-l-8">元</span>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '2'">
            <span>{{
              sumData.safePayTransServicePrice
                ? sumData.safePayTransServicePrice
                : "0"
            }}</span>
            <span class="m-l-8">元</span>
          </div>
        </div>

        <div class="sumItem">
          <span class="m-t-8">平均费率</span>
          <div class="sumdata1">
            <span>{{ sumData.averageRate ? sumData.averageRate : "0" }}%</span>
            <span class="m-l-8">/笔</span>
          </div>
        </div>

        <div class="sumItem">
          <span class="m-t-8">到卡金额</span>
          <div class="sumdata2" v-if="chartsType1 === '0'">
            <div class="m-t-8">
              <span>P：</span>
              <span>0 元</span>
            </div>
            <div class="m-t-8">
              <span>A：</span>
              <span
                >{{
                  sumData.safePayTransSuccessBankAmount
                    ? sumData.safePayTransSuccessBankAmount
                    : "0"
                }}
                元</span
              >
            </div>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '1'">
            <span>0</span>
            <span class="m-l-8">元</span>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '2'">
            <span>{{
              sumData.safePayTransSuccessBankAmount
                ? sumData.safePayTransSuccessBankAmount
                : "0"
            }}</span>
            <span class="m-l-8">元</span>
          </div>
        </div>

        <div class="sumItem">
          <span class="m-t-8">到支付宝金额</span>
          <div class="sumdata2" v-if="chartsType1 === '0'">
            <div class="m-t-8">
              <span>P：</span>
              <span
                >{{
                  sumData.payTransSuccessAmount
                    ? sumData.payTransSuccessAmount
                    : "0"
                }}
                元</span
              >
            </div>

            <div class="m-t-8">
              <span>A：</span>
              <span
                >{{
                  sumData.safePayTransSuccessAlipayAmount
                    ? sumData.safePayTransSuccessAlipayAmount
                    : "0"
                }}
                元</span
              >
            </div>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '1'">
            <span>{{
              sumData.payTransSuccessAmount
                ? sumData.payTransSuccessAmount
                : "0"
            }}</span>
            <span class="m-l-8">元</span>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '2'">
            <span>{{
              sumData.safePayTransSuccessAlipayAmount
                ? sumData.safePayTransSuccessAlipayAmount
                : "0"
            }}</span>
            <span class="m-l-8">元</span>
          </div>
        </div>
      </div>

      <!-- 内容 4-->
      <div class="sumBox">
        <div class="sumItem">
          <span class="m-t-8">付款支付宝账户数</span>
          <div class="sumdata2" v-if="chartsType1 === '0'">
            <div class="m-t-8">
              <span>P：</span>
              <span
                >{{
                  sumData.payTransPayerAlipayAccountCount
                    ? sumData.payTransPayerAlipayAccountCount
                    : "0"
                }}
                个</span
              >
            </div>

            <div class="m-t-8">
              <span>A：</span>
              <span
                >{{
                  sumData.safePayPayerAlipayAccountCount
                    ? sumData.safePayPayerAlipayAccountCount
                    : "0"
                }}
                个</span
              >
            </div>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '1'">
            <span>{{
              sumData.payTransPayerAlipayAccountCount
                ? sumData.payTransPayerAlipayAccountCount
                : "0"
            }}</span>
            <span class="m-l-8">个</span>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '2'">
            <span>{{
              sumData.safePayPayerAlipayAccountCount
                ? sumData.safePayPayerAlipayAccountCount
                : "0"
            }}</span>
            <span class="m-l-8">个</span>
          </div>
        </div>

        <div class="sumItem">
          <span class="m-t-8">收款支付宝账户数</span>
          <div class="sumdata2" v-if="chartsType1 === '0'">
            <div class="m-t-8">
              <span>P：</span>
              <span
                >{{
                  sumData.payTransPayeeAlipayAccountCount
                    ? sumData.payTransPayeeAlipayAccountCount
                    : "0"
                }}
                个</span
              >
            </div>

            <div class="m-t-8">
              <span>A：</span>
              <span
                >{{
                  sumData.safePayPayeeAlipayAccountCount
                    ? sumData.safePayPayeeAlipayAccountCount
                    : "0"
                }}
                个</span
              >
            </div>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '1'">
            <span>{{
              sumData.payTransPayeeAlipayAccountCount
                ? sumData.payTransPayeeAlipayAccountCount
                : "0"
            }}</span>
            <span class="m-l-8">个</span>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '2'">
            <span>{{
              sumData.safePayPayeeAlipayAccountCount
                ? sumData.safePayPayeeAlipayAccountCount
                : "0"
            }}</span>
            <span class="m-l-8">个</span>
          </div>
        </div>

        <div class="sumItem">
          <span class="m-t-8">付款超过500万的账户数</span>
          <div class="sumdata2" v-if="chartsType1 === '0'">
            <div class="m-t-8">
              <span>P：</span>
              <span
                >{{
                  sumData.payTransVeryAlipayUserCount
                    ? sumData.payTransVeryAlipayUserCount
                    : "0"
                }}
                个</span
              >
            </div>

            <div class="m-t-8">
              <span>A：</span>
              <span
                >{{
                  sumData.safePayTransVeryAlipayUserCount
                    ? sumData.safePayTransVeryAlipayUserCount
                    : "0"
                }}
                个</span
              >
            </div>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '1'">
            <span>{{
              sumData.payTransVeryAlipayUserCount
                ? sumData.payTransVeryAlipayUserCount
                : "0"
            }}</span>
            <span class="m-l-8">个</span>
          </div>

          <div class="sumdata1" v-if="chartsType1 === '2'">
            <span>{{
              sumData.safePayTransVeryAlipayUserCount
                ? sumData.safePayTransVeryAlipayUserCount
                : "0"
            }}</span>
            <span class="m-l-8">个</span>
          </div>
        </div>
      </div>

      <!-- 商户列表 -->
      <!-- 标题 -->
      <div class="title1">
        <span>商户列表</span>
      </div>
      <!-- searchModel -->
      <div>
        <el-card shadow="never" class="m-b-8">
          <div>
            <el-form :inline="true" size="mini" class="demo-form-inline">
              <el-radio-group
                v-if="searchModel.dataType === ''"
                v-model="searchModel.type"
                @change="realTimeGetList(1)"
              >
                <el-radio-button label="0">付款笔数排行榜</el-radio-button>
                <el-radio-button label="1">付款金额排行榜</el-radio-button>
                <el-radio-button label="2">付款失败排行榜</el-radio-button>
                <el-radio-button
                  label="3"
                  v-if="
                    searchModel.dataType === '1' || searchModel.dataType === '2'
                  "
                  >未活跃商户排行榜</el-radio-button
                >
              </el-radio-group>

              <el-radio-group
                v-if="searchModel.dataType !== ''"
                v-model="searchModel.type"
                @change="getList(1)"
              >
                <el-radio-button label="0">付款笔数排行榜</el-radio-button>
                <el-radio-button label="1">付款金额排行榜</el-radio-button>
                <el-radio-button label="2">付款失败排行榜</el-radio-button>
                <el-radio-button
                  label="3"
                  v-if="
                    searchModel.dataType === '1' || searchModel.dataType === '2'
                  "
                  >未活跃商户排行榜</el-radio-button
                >
              </el-radio-group>

              <el-form-item class="m-l-8" style="float: right">
                <el-button type="danger" plain @click="gettotalList(1)"
                  >历史总量</el-button
                >
              </el-form-item>

              <el-form-item class="m-l-8" style="float: right">
                <el-radio-group
                  v-model="searchModel.dataType"
                  size="small"
                  @change="switchGetList(1)"
                >
                  <el-radio-button label="">今日</el-radio-button>
                  <el-radio-button label="1">昨日</el-radio-button>
                  <el-radio-button label="2">月</el-radio-button>
                </el-radio-group>
              </el-form-item>

           
            </el-form>
          </div>
        </el-card>
      </div>
      <!-- 时间 -->
      <div class="m-t-16" v-if="searchModel.dataType === ''">
        <span class="m-l-8">更新时间：{{ extra ? extra : "-" }}</span>
      </div>

      <!-- 时间 -->
      <div class="m-t-16" v-if="searchModel.dataType === '0'">
        <span class="m-l-8">最早时间-昨日</span>
      </div>

      <!-- 时间 -->
      <div class="m-t-16" v-if="searchModel.dataType === '1'">
        <span class="m-l-8">昨日：{{ yesterday }}</span>
      </div>

      <!-- 时间 -->
      <div class="m-t-16" v-if="searchModel.dataType === '2'">
        <span class="m-l-8" v-if="dayOfMonth != 1"
          >{{ monthStart }}~{{ yesterday }}</span
        >
        <span class="m-l-8" v-if="dayOfMonth == 1">月数据每月1号以后生成</span>
      </div>

      <!-- 内容 -->
      <div class="data-list-wrap m-t-16">
        <el-card shadow="never">
          <el-table
            size="mini"
            v-loading="loading"
            :data="list"
            style="width: 100%"
          >
            <el-table-column prop="userId" label="商户编号" width="100">
            </el-table-column>

            <el-table-column label="商户名称">
              <template slot-scope="scope">
                <span>{{ scope.row.name ? scope.row.name : "-" }}</span>
              </template>
            </el-table-column>

            <el-table-column label="合伙人名称">
              <template slot-scope="scope">
                <span>{{ scope.row.partnerName ? scope.row.partnerName : "-" }}</span>
              </template>
            </el-table-column>

            <el-table-column label="付款笔数" v-if="searchModel.type === '0'">
              <template slot-scope="scope">
                {{ scope.row.totalSuccessCount }}
              </template>
            </el-table-column>

            <el-table-column
              label="付款金额单笔超过1万元的笔数"
              v-if="searchModel.type === '0'"
            >
              <template slot-scope="scope">
                {{ scope.row.totalSuccessLargeCount }}
              </template>
            </el-table-column>

            <el-table-column label="付款金额" v-if="searchModel.type === '1'">
              <template slot-scope="scope">
                {{ scope.row.totalSuccessTransAmount }}
              </template>
            </el-table-column>

            <el-table-column label="总付款笔数" v-if="searchModel.type === '2'">
              <template slot-scope="scope">
                {{ scope.row.totalCount }}
              </template>
            </el-table-column>

            <el-table-column label="失败笔数" v-if="searchModel.type === '2'">
              <template slot-scope="scope">
                {{ scope.row.totalFailCount }}
              </template>
            </el-table-column>

            <el-table-column label="失败占比" v-if="searchModel.type === '2'">
              <template slot-scope="scope">
                {{ scope.row.failRate }} %
              </template>
            </el-table-column>

            <el-table-column
              label="前日付款金额"
              v-if="searchModel.type === '3' && searchModel.dataType === '1'"
            >
              <template slot-scope="scope">
                {{ scope.row.beforeYestAmount }}
              </template>
            </el-table-column>

            <el-table-column
              label="日差额"
              v-if="searchModel.type === '3' && searchModel.dataType === '1'"
            >
              <template slot-scope="scope">
                {{ scope.row.increase }}
              </template>
            </el-table-column>

            <el-table-column
              label="月差额"
              v-if="searchModel.type === '3' && searchModel.dataType === '2'"
            >
              <template slot-scope="scope">
                {{ scope.row.increase }}
              </template>
            </el-table-column>

            <el-table-column
              label="上月付款金额"
              v-if="searchModel.type === '3' && searchModel.dataType === '2'"
            >
              <template slot-scope="scope">
                {{ scope.row.yestAmount }}
              </template>
            </el-table-column>
          </el-table>

          <div class="paging-wrap">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="searchModel.pageNo"
              :page-sizes="[10, 20, 50, 100]"
              :page-size="searchModel.pagesize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="searchModel.count"
            >
            </el-pagination>
          </div>

        </el-card>
      </div>
    </div>
  </div>
</template>

<script>
import moment from "moment";
import { mapGetters } from "vuex";
import adminDashboard from "./admin";
import { count } from "@/api/visits";
import {
  sumCompanyDailyStat,
  selectCompanyRealTimeStat,
  aggSearchUserDailyStat,
  aggSearchUserRealTimeStat,
} from "../../api/business";
const defaultModel = {
  dataType: "",
  type: "0",
  pageNo: 1,
  pageSize: 10,
  count: 0,
};
export default {
  name: "Dashboard",
  components: { adminDashboard },
  data() {
    return {
      currentRole: "adminDashboard",
      searchModel: _.cloneDeep(defaultModel),
      sumData: {},
      loading: false,
      dataType: "",
      dataType1: "",
      dataType2: "",
      chartsType1: "0",
      chartsType2: "0",
      extra: "",
      type: "",
      list: [],
      dayOfMonth: moment().date(),
      yesterday: moment().subtract(1, "days").format("YYYY-MM-DD"),
      monthStart: moment().startOf("month").format("YYYY-MM-DD"),
    };
  },
  computed: {
    ...mapGetters(["roles"]),
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.realTimeGetList(1);
      this.getDailyInfo();
    },
    //实时查询日统计
    getDailyInfo() {
      selectCompanyRealTimeStat().then((resp) => {
        if (resp.success) {
          this.sumData = resp.data;
        }
      });
    },

    //经营数据切换查询日统计
    switchInfo() {
      if (this.dataType2 === "") {
        selectCompanyRealTimeStat().then((resp) => {
          if (resp.success) {
            this.sumData = resp.data;
          }
        });
      } else {
        let form = {
          dataType: this.dataType2,
        };
        sumCompanyDailyStat(form).then((resp) => {
          if (resp.success) {
            this.sumData = resp.data;
          }
        });
      }
    },

    //历史总量查询日统计
    totalSwitchInfo() {
      this.dataType2 = "0";
      let form = {
        dataType: "0",
      };
      sumCompanyDailyStat(form).then((resp) => {
        if (resp.success) {
          this.sumData = resp.data;
        }
      });
    },
    //历史总量查询商户数据
    gettotalList(pageNo) {
      var self = this;
      this.loading = true;
      if (pageNo != undefined) {
        this.searchModel.pageNo = pageNo;
      }
      self.searchModel.dataType = "0";
      let searchModel = _.cloneDeep(this.searchModel);
      aggSearchUserDailyStat(this.compileSearchModel(searchModel))
        .then((data) => {
          self.searchModel.pageNo = ++data.pageNo;
          self.searchModel.count = data.count;
          self.searchModel.pageSize = data.pageSize;
          self.list = data.data;

          self.loading = false;
        })
        .catch((err) => {});
    },

    switchGetList(pageNo) {
      var self = this;
      this.loading = true;
      if (pageNo != undefined) {
        this.searchModel.pageNo = pageNo;
      }
      let searchModel = _.cloneDeep(this.searchModel);
      if (this.searchModel.dataType === "") {
        aggSearchUserRealTimeStat(this.compileSearchModel(searchModel))
          .then((data) => {
            self.searchModel.pageNo = ++data.pageNo;
            self.searchModel.count = data.count;
            self.searchModel.pageSize = data.pageSize;
            self.list = data.data;
            this.extra = data.extra;
            self.loading = false;
          })
          .catch((err) => {});
      } else {
        aggSearchUserDailyStat(this.compileSearchModel(searchModel))
          .then((data) => {
            self.searchModel.pageNo = ++data.pageNo;
            self.searchModel.count = data.count;
            self.searchModel.pageSize = data.pageSize;
            self.list = data.data;
            self.loading = false;
          })
          .catch((err) => {});
      }
    },
    //查询商户数据
    getList(pageNo) {
      var self = this;
      this.loading = true;
      if (pageNo != undefined) {
        this.searchModel.pageNo = pageNo;
      }
      let searchModel = _.cloneDeep(this.searchModel);
      aggSearchUserDailyStat(this.compileSearchModel(searchModel))
        .then((data) => {
          self.searchModel.pageNo = ++data.pageNo;
          self.searchModel.count = data.count;
          self.searchModel.pageSize = data.pageSize;
          self.list = data.data;
          self.loading = false;
        })
        .catch((err) => {});
    },

    //实时查询商户数据
    realTimeGetList(pageNo) {
      var self = this;
      this.loading = true;
      if (pageNo != undefined) {
        this.searchModel.pageNo = pageNo;
      }
      let searchModel = _.cloneDeep(this.searchModel);
      aggSearchUserRealTimeStat(this.compileSearchModel(searchModel))
        .then((data) => {
          self.searchModel.pageNo = ++data.pageNo;
          self.searchModel.count = data.count;
          self.searchModel.pageSize = data.pageSize;
          self.list = data.data;
          self.loading = false;
          this.extra = data.extra;
        })
        .catch((err) => {});
    },

    //搜索条件处理
    compileSearchModel(searchModel) {
      searchModel.pageNo = searchModel.pageNo - 1;

      if (!this.isToday && searchModel.day && searchModel.day.length) {
        searchModel["minDay"] = searchModel.day[0];
        searchModel["maxDay"] = searchModel.day[1];
      }
      delete searchModel.day;

      return searchModel;
    },
    //重置
    reset() {
      this.isToday = 0;
      this.searchModel = _.cloneDeep(defaultModel);
      this.getList();
    },
    //修改分页
    handleSizeChange(val) {
      this.searchModel.pageSize = val;
      this.switchGetList(1)
    },
    //修改页面
    handleCurrentChange(val) {
      this.switchGetList(val);
    },
  },
};
</script>


<style lang="scss" scoped>
.title1 {
  padding: 24px 0 24px 0;
  font-size: 22px;
  font-weight: 600;
}

.sumBox {
  display: grid;
  grid-template-columns: repeat(4, 25%);
  padding: 2px;
  .sumItem1 {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    align-items: center;
    margin-right: 16px;
    margin-top: 16px;
    height: 150px;
    padding: 16px;
    background-color: #fde2e2;
    box-sizing: border-box;
    font-weight: 600;
  }
  .sumItem {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    align-items: center;
    margin-right: 16px;
    margin-top: 16px;
    height: 150px;
    padding: 16px;
    background-color: #fff;
    box-sizing: border-box;
    font-weight: 600;

    .sumdata {
      width: 100%;
      height: 100px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      font-size: 20px;
      font-weight: 600;
    }

    .sumdata1 {
      width: 100%;
      height: 118px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 20px;
      font-weight: 600;
    }

    .sumdata2 {
      width: 100%;
      height: 118px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      font-size: 14px;
      font-weight: 600;
    }

    .sumdata3 {
      width: 100%;
      height: 118px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 20px;
      font-weight: 600;
    }
  }
}
</style>
